<template>
  <div>
    <el-container>
      <el-header>
        <h1>后台管理系统</h1>
        <el-button size="medium" @click="loginout">退出</el-button>
      </el-header>
      <el-container>
        <el-aside :width="flag?'64px':'201px'">
              <div class="flag" @click="flag = !flag">|||</div>
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            unique-opened
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            router
            :collapse="flag"
          >
      
            <el-submenu :index="item.order+''" v-for="(item,index) in list" :key="index">
              <template slot="title">
                <i :class="icon[item.id]"></i>
                <span style="margin:0 40px 0 10px">{{item.authName}}</span>
              </template>
       
              <el-menu-item :index="item.path" v-for="(item,index) in item.children" :key="index">
                <i class="el-icon-menu"></i>
             {{item.authName}}
              </el-menu-item>
      
            </el-submenu>

          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "",
  // 组件注册
  components: {},
  // 父组件传参
  props: {},
  // 变量声明
  data() {
    return {
      flag:false,
      list:[],
      icon:{
         '125':"el-icon-s-custom" ,
         '103':"el-icon-bank-card" ,
         '101':"el-icon-shopping-bag-2",
         '102':"el-icon-notebook-2" ,
        '145':"el-icon-s-platform"} 
          
    };
  },
  // Vue实例创建完成以后执行 数据可用
  created() {
    this.getLeftmenu()
  },
  // Vue模板挂载完毕以后执行  DOM节点加载完毕了（可以获取节点了）
  mounted() {},
  // keepalive 缓存进入执行
  activited() {},
  // vue组件更新完毕以后执行
  update() {},
  // 定义事件
  methods: {
   async getLeftmenu(){
    let res =  await this.$axios.get("menus");
      let { data,meta} =res.data
    if(meta.status == 200){
      this.list = data
    console.log(this.list)

    }
    },
    loginout(){
      sessionStorage.clear()
      this.$router.push("/")
      this.$message.success("退出成功")
    },


  },
  // 过滤器
  filter: {},
  // 计算属性
  computed: {},
  // 监听属性
  watch: {},
};
</script>

<style lang="less" scoped>
.el-header {
  background-color: #545c64;
  color: #333;
  // display: flex;
  h1 {
    margin: 0;
    height: 60px;
    line-height: 60px;
    color: #fff;
    float: left;
  }
  .el-button {
    margin-top: 10px;
    float: right;
  }
}

.el-aside {
  background-color: #545c64;
  color: #333;
  text-align: center;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}
div,
.el-container {
  height: 100%;
}
.flag{
  height: 24px;
    line-height: 24px;
    background-color: #4a5064;
    font-size: 20px;
    text-align: center;
    color: #fff;
    letter-spacing: .02em;
    cursor: pointer;
}
</style>
